home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Documents / Tutorial / Examples / SimpleApp5.c < prev   
Text File  |  1996-01-17  |  2KB  |  140 lines

  1. # include   "TransSkel.h"
  2.  
  3.  
  4. static char lastChar = '\0';
  5. static Point lastLocation = { 20, 20 };
  6.  
  7.  
  8. static pascal void
  9. DoFileMenu (short item)
  10. {
  11.     SkelStopEventLoop ();            /* tell SkelEventLoop() to quit */
  12. }
  13.  
  14.  
  15. static pascal void
  16. Mouse (Point where, long when, short modifiers)
  17. {
  18. WindowPtr    w;
  19.  
  20.     lastLocation = where;
  21.     GetPort (&w);
  22.     InvalRect (&w->portRect);
  23. }
  24.  
  25.  
  26. static pascal void
  27. Key (short c, short code, short modifiers)
  28. {
  29. WindowPtr    w;
  30.  
  31.     lastChar = c;
  32.     GetPort (&w);
  33.     InvalRect (&w->portRect);
  34. }
  35.  
  36.  
  37. static void
  38. DrawGrowBox (WindowPtr w)
  39. {
  40. RgnHandle    oldClip;
  41. Rect        r;
  42.  
  43.     r = w->portRect;
  44.     r.left = r.right - 15;        /* draw only in corner */
  45.     r.top = r.bottom - 15;
  46.     oldClip = NewRgn ();
  47.     GetClip (oldClip);
  48.     ClipRect (&r);
  49.     DrawGrowIcon (w);
  50.     SetClip (oldClip);
  51.     DisposeRgn (oldClip);
  52. }
  53.  
  54.  
  55. static pascal void
  56. Update (Boolean resized)
  57. {
  58. WindowPtr    w;
  59.  
  60.     GetPort (&w);
  61.     EraseRect (&w->portRect);
  62.     if (lastChar != '\0')
  63.     {
  64.         MoveTo (lastLocation.h, lastLocation.v);
  65.         DrawChar (lastChar);
  66.     }
  67.     DrawGrowBox (w);
  68. }
  69.  
  70.  
  71. static pascal void
  72. Activate (Boolean active)
  73. {
  74. WindowPtr    w;
  75.  
  76.     GetPort (&w);
  77.     DrawGrowBox (w);
  78. }
  79.  
  80.  
  81. static pascal void
  82. Close (void)
  83. {
  84.     SkelStopEventLoop ();
  85. }
  86.  
  87.  
  88. static pascal void
  89. Clobber (void)
  90. {
  91. WindowPtr    w;
  92.  
  93.     GetPort (&w);
  94.     DisposeWindow (w);
  95. }
  96.  
  97.  
  98. static pascal void
  99. Idle (void)
  100. {
  101. WindowPtr    w;
  102.  
  103.     GetPort (&w);
  104. }
  105.  
  106.  
  107. int
  108. main (void)
  109. {
  110. MenuHandle    m;
  111. WindowPtr    w;
  112. Rect        r;
  113.  
  114.     SkelInit (nil);                /* initialize */
  115.     SkelApple (nil, nil);        /* handle Apple menu */
  116.     /* create File menu, install handler */
  117.     m = NewMenu (skelAppleMenuID + 1, "\pFile");
  118.     AppendMenu (m, "\pQuit/Q");
  119.     (void) SkelMenu (m,                    /* menu handle */
  120.                         DoFileMenu,        /* item selection function */
  121.                         nil,            /* menu disposal function */
  122.                         false,            /* not a submenu */
  123.                         true);            /* draw menu bar */
  124.  
  125.     SetRect (&r, 40, 40, 200, 120);
  126.     w = NewWindow (nil, &r, "\pA Window", true,
  127.                         documentProc+8, (WindowPtr) -1, true, 0L);
  128.     (void) SkelWindow (w,
  129.                         Mouse,        /* mouse click handler */
  130.                         Key,        /* key click handler */
  131.                         Update,        /* update event handler */
  132.                         Activate,    /* activate event handler */
  133.                         Close,        /* close box click handler */
  134.                         Clobber,    /* disposal function */
  135.                         Idle,        /* idle-time handler */
  136.                         true);        /* idle only when frontmost */
  137.     SkelEventLoop ();
  138.     SkelCleanup ();
  139. }
  140.